import { Component, Prop } from 'vue-facing-decorator'
import Render from '@/render/Render'
import toNative from '@/utils/toNative'
import { PeriodRecharge } from './Period'
import type { CompanyDetailDto } from '@/api/company/types'
import { getModelValue } from '@/components/modal/Modal'
import { message } from 'ant-design-vue'
import { rechargeWesureAccount } from '@/api/company'

@Component
export class DailyRecharge extends PeriodRecharge {
    title = '充值日日保'

    async onSubmit() {
        const data = getModelValue(this.rechargeFormConfig)
        data.companyId = this.companyDetail.companyId
        if (data.voucherUrl?.length && Array.isArray(data.voucherUrl)) {
            data.voucherUrl = data.voucherUrl[0].base64
        }
        await rechargeWesureAccount(data)
        message.success('更新成功')
        this.successHint = `已成功为「${this.companyDetail.companyName}」充值了日日保账户，可在「充值审批」中查看结果`
        this.isSuccess = true
    }

    render() {
        return <>{super.render()}</>
    }
}

export default toNative<{
    companyDetail: CompanyDetailDto
}, {}>(DailyRecharge)